#include <QGroupBox>
#include <QVBoxLayout>
#include <QFormLayout>

#include "biblereaderconfigbiblepage.h"

BibleReaderConfigBiblePage::BibleReaderConfigBiblePage(BibleReaderConfigurator *cfg, QWidget *parent) : QWidget(parent)
{
    configurator = cfg;

    QGroupBox *bibleBox = new QGroupBox(tr("Bible Setting"), this);
    QFormLayout *bibleLayout = new QFormLayout(bibleBox);
    showXrefCB = new QCheckBox(this);
    showXrefCB->setChecked(configurator->getIsShowXref());

    bibleLayout->addRow(tr("Show Xref:"), showXrefCB);
    connect(showXrefCB, &QCheckBox::toggled, this, &BibleReaderConfigBiblePage::isShowXrefChanged);

    // verse title copy style
    copyVerseTitleStyleCB = new QComboBox(this);
    copyVerseTitleStyles << tr("(book chapter:verse) + verse text")
                         << tr("[book chapter:verse] + verse text")
                         << tr("verse text + (book chapter:verse)")
                         << tr("verse text + [book chapter:verse]")
                         << tr("No verse header");
    copyVerseTitleStyleCB->addItems(copyVerseTitleStyles);
    copyVerseTitleStyleCB->setCurrentIndex(configurator->getVerseCopyTitleStyle());
    connect(copyVerseTitleStyleCB, SIGNAL(currentIndexChanged(int)), this, SLOT(copyVerseTitleStyleChanged(int)));
    bibleLayout->addRow(tr("Copy verse title style:"), copyVerseTitleStyleCB);

    QVBoxLayout *vboxLayout = new QVBoxLayout(this);
    vboxLayout->addWidget(bibleBox);


}

BibleReaderConfigBiblePage::~BibleReaderConfigBiblePage()
{
    if (showXrefCB) {
        delete showXrefCB;
    }
}

void BibleReaderConfigBiblePage::isShowXrefChanged(bool show)
{
    configurator->setIsShowXref(show);
}

void BibleReaderConfigBiblePage::copyVerseTitleStyleChanged(int style)
{
    configurator->setVerseCopyTitleStyle(style);
}
